#coding=utf-8

import gtk,pynotify

def on_activate(tray):
    pynotify.init("Basics")
    n = pynotify.Notification("Summary", "This is some sample content")

    
    # set position of bubble pop-up under system tray icon
    s,a,o = tray.get_geometry()
    #print a.x
    #print a.y
    n.set_hint("x",a.x + (a.width / 2))
    n.set_hint("y",a.y + a.height - 10)
    
    n.show()
    
def on_popup_menu(tray, button, activate_time):
    print 'pop up menu.'        

class StTray(object):
    
    def __init__(self, win):
    
        self.win = win
        
        self.tray = gtk.status_icon_new_from_file('eyes.png')
        
        self.tray.connect("activate", self.on_activate)
        self.tray.connect('popup-menu', self.on_popup_menu)
        
    def on_activate(self, tray):
        
        if self.tray.get_blinking():
            self.tray.set_blinking(False)
            
        state = self.win.get_property('visible')
        
        if state: self.win.hide()
        else:
            if self.win.is_iconfied:
                self.win.deiconify()
                self.win.is_iconfied = False
                
            self.win.show()
            
    
    def on_popup_menu(self, tray, button, activate_time):
        print 'pop up menu.'
    
    def warnning(self, msg):
    
        pynotify.init("Basics")
        n = pynotify.Notification("注意!", msg)

        # set position of bubble pop-up under system tray icon
        s,a,o = self.tray.get_geometry()
        
        n.set_hint("x",a.x + (a.width / 2))
        n.set_hint("y",a.y + a.height - 10)
        
        n.show()
        
        #闪烁
        self.tray.set_blinking(True)
